package br.com.mmm.javacenter.framework.reflection.injectors;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import br.com.mmm.javacenter.framework.annotations.InjectorComponent;
import br.com.mmm.javacenter.framework.formatters.DateFormat;
import br.com.mmm.javacenter.framework.reflection.ReflectionFacade;


@InjectorComponent({Calendar.class,GregorianCalendar.class})
public class GregorianCalendarInjector implements Injector{
	public void inject(ReflectionFacade rf,String field, Object value) {
		if(value!=null){
			try{
				Date parse = DateFormat.simpleDate.parse(value.toString());
				Calendar calendar =  new GregorianCalendar();
				calendar.setTime(parse);
				rf.set(field, calendar);
			}catch(Exception e){
				rf.set(field, null);
			}
		}
	}

}
